[#import "/framework/JGP.htm"  as JGP]
<!--
项目   parent
作者   LOUFEI [Gavin]
时间   2018/5/7
-->
[@JGP.head "Title"/]
[@JGP.body]


<jgp-div slot="1-1" _row="['40','*']" _runit="px">

    <div slot="1-1">
        <jgp-btn _fn="saveCallback">确定</jgp-btn>
        <jgp-btn _fn="modify">修改/锁定</jgp-btn>
    </div>
    <jgp-panel slot="2-1">
        <jgp-tree2 _id="roleTree" _root="角色树" _check="true" _icon="false"
                   _onload="initTree"
                   _enable="false"
                   _single="${isSingle?c}"
                   _url="/security/admin/adminApiController/treeRole"></jgp-tree2>
    </jgp-panel>
</jgp-div>


[/@JGP.body]

[@JGP.foot]
    <script>
        function initTree(){
            JGP.$get('/security/admin/adminApiController/queryUserRoles/${userId!''}', {},
                    function (result) {
                        const selected = result.data.roleIds;
                        JGP.tree2('roleTree').setSelectedKeys(selected);
                    })
        }

        function saveCallback() {
            var selected = JGP.tree2('roleTree').getSelected();
            if (selected === -1) {
                JGP.$warn('没有选择角色');
                return;
            }

            var roles = [];
            for (var i = 0; i < selected.length; i++) {
                roles.push(selected[i]);
            }
            JGP.$close(roles);

        }
        function modify(){
            JGP.tree2('roleTree').setEnable(true);
        }
    </script>
[/@JGP.foot]